package com.hnucm.cooklife.model;

import com.hnucm.cooklife.base.BaseModel;
import com.hnucm.cooklife.bean.db.Dish;
import com.hnucm.cooklife.bean.db.History;
import com.hnucm.cooklife.bean.me.DishColl;
import com.hnucm.cooklife.contract.history.Contract;

import java.util.ArrayList;
import java.util.List;

import io.reactivex.Observable;

public class HistoryModel extends BaseModel implements Contract.IHistoryModel {
    @Override
    public Observable<List<DishColl>> loadHistory(int userId) {
        return mApiServer.getHistroy(userId)
                .map(historyData -> {
                    List<DishColl> historyList = new ArrayList<>();
                    historyData.getData().stream().forEach(dataDTO -> {


                        DishColl history = new DishColl();
//                        history.bg = dataDTO.getBg();
                        history.dishname = dataDTO.getDishname();
                        history.collect = dataDTO.getCollect();
                        history.dishId = dataDTO.getDishId();
                        history.dishdesc = dataDTO.getDishdesc();
                        history.dishdone = dataDTO.getDishdone();
                        history.dishpic = dataDTO.getDishpic();
                        history.icon = dataDTO.getIcon();
                        history.username = dataDTO.getUsername();
                        history.userid = dataDTO.getUserid();
                        historyList.add(history);

                    });
                    return historyList;
                });
    }

    @Override
    public Observable<List<DishColl>> refresgHistory(int userId) {
        return null;
    }
}
